package com.atguigu.study.config;

import com.atguigu.study.service.ChatAssistant;
import com.atguigu.study.service.LawAssistant;
import dev.langchain4j.model.chat.ChatModel;
import dev.langchain4j.model.chat.StreamingChatModel;
import dev.langchain4j.model.openai.OpenAiChatModel;
import dev.langchain4j.model.openai.OpenAiStreamingChatModel;
import dev.langchain4j.service.AiServices;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Marco
 * @Description
 * @date 2025/8/20 21:20
 * @email 3293336923@qq.com
 */
@Configuration
public class LLMConfig {

//    低阶的 api
    @Bean
    public ChatModel   chatModel(){
        return
                OpenAiChatModel.builder()
                        .apiKey(System.getenv("ALIQW"))
                        .modelName("qwen-long")
                        .baseUrl("https://dashscope.aliyuncs.com/compatible-mode/v1")
                        .build();
    }


    /***
     *  流式对话接口
     * @return
     */
    @Bean
    public StreamingChatModel streamingChatModel(){
        return
                OpenAiStreamingChatModel.builder()
                        .apiKey(System.getenv("ALIQW"))
                        .modelName("qwen-plus")
                        .baseUrl("https://dashscope.aliyuncs.com/compatible-mode/v1")
                        .build();
    }


    @Bean
    public LawAssistant   lawAssistant(ChatModel   chatModel){
        return
                AiServices.create(LawAssistant.class , chatModel);
    }




//    结合 流式返回给 前台，更好的 用户体验
    @Bean
    public ChatAssistant  chatAssistant(StreamingChatModel streamingChatModel){
        return   AiServices.create(ChatAssistant.class , streamingChatModel);
    }



}
